package com.example.mcpclient.config;

import org.springframework.ai.chat.client.ChatClientRequest;
import org.springframework.ai.chat.client.ChatClientResponse;
import org.springframework.ai.chat.client.advisor.api.AdvisorChain;
import org.springframework.ai.chat.client.advisor.api.BaseAdvisor;
import org.springframework.ai.chat.client.advisor.api.CallAdvisor;
import org.springframework.ai.chat.client.advisor.api.CallAdvisorChain;
import org.springframework.stereotype.Component;

/**
 * 更精确控制 HTTP headers 的 GroupIdHeaderAdvisor 实现
 */
@Component("groupIdAdvisor")
public class GroupIdHeaderAdvisor implements BaseAdvisor {


    @Override
    public String getName() {
        return "groupIdAdvisor";
    }

    @Override
    public ChatClientRequest before(ChatClientRequest chatClientRequest, AdvisorChain advisorChain) {
        // 方法1: 通过上下文传递参数
        // 继续执行调用链
        return chatClientRequest.mutate().context("groupId", "110110").build();
    }

    @Override
    public ChatClientResponse after(ChatClientResponse chatClientResponse, AdvisorChain advisorChain) {
        return chatClientResponse;
    }


    @Override
    public int getOrder() {
        return -100;
    }
}
